//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: V_CrmDeliverMajorProductLayout.cs
// 作 者：代码自动生成
// 日 期：2012-4-1 11:15:37
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
	/// <summary>
    /// 
    /// </summary>
	[Serializable]
    [Table(Name="V_CrmDeliverMajorProductLayout")]
    [ZX.DBModule.Table("V_CrmDeliverMajorProductLayout", "ID")]
	public class V_CrmDeliverMajorProductLayout: ZX.DBModule.BaseEntity
	{
        #region Business Methods 业务方法
        /// <summary>
        /// 主键ID
        /// </summary>
        private static PropertyInfo<Guid> IDProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<Guid>("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        /// <summary>
        /// 交付单单号
        /// </summary>
        private static PropertyInfo<string> CodeProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<string>("Code"));
        [Column]
        public string Code
        {
            get { return GetProperty(CodeProperty); }
            set { SetProperty(CodeProperty, value); }
        }
        /// <summary>
        /// 客户编码
        /// </summary>
        private static PropertyInfo<string> CustomercodeProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<string>("CustomerCode"));
        [Column]
        public string CustomerCode
        {
            get { return GetProperty(CustomercodeProperty); }
            set { SetProperty(CustomercodeProperty, value); }
        }
        /// <summary>
        /// 客户ID
        /// </summary>
        private static PropertyInfo<string> CustomerIdProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<string>("CustomerId"));
        [Column]
        public string CustomerId
        {
            get { return GetProperty(CustomerIdProperty); }
            set { SetProperty(CustomerIdProperty, value); }
        }
        
		/// <summary>
        /// 订单产品ID
        /// </summary>
        private static PropertyInfo< Guid > OrderProductIDProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("OrderProductID"));
        [Column]
        public Guid OrderProductID
        {
            get { return GetProperty(OrderProductIDProperty); }
            set { SetProperty(OrderProductIDProperty, value); }
        }
		/// <summary>
        /// 产品规划ID
        /// </summary>
        private static PropertyInfo< Guid > ProductLayoutIDProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("ProductLayoutID"));
        [Column]
        public Guid ProductLayoutID
        {
            get { return GetProperty(ProductLayoutIDProperty); }
            set { SetProperty(ProductLayoutIDProperty, value); }
        }
		/// <summary>
        /// 谈单老师
        /// </summary>
        private static PropertyInfo< Guid > NegotiateTeachProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("NegotiateTeach"));
        [Column]
        public Guid NegotiateTeach
        {
            get { return GetProperty(NegotiateTeachProperty); }
            set { SetProperty(NegotiateTeachProperty, value); }
        }
		/// <summary>
        /// 课中服务人
        /// </summary>
        private static PropertyInfo< Guid > ClassServerProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("ClassServer"));
        [Column]
        public Guid ClassServer
        {
            get { return GetProperty(ClassServerProperty); }
            set { SetProperty(ClassServerProperty, value); }
        }
		/// <summary>
        /// 负责交付人
        /// </summary>
        private static PropertyInfo< Guid > ClassFrontServerProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("ClassFrontServer"));
        [Column]
        public Guid ClassFrontServer
        {
            get { return GetProperty(ClassFrontServerProperty); }
            set { SetProperty(ClassFrontServerProperty, value); }
        }
		/// <summary>
        /// 交付单状态
        /// </summary>
        private static PropertyInfo< Guid > DliverStateProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("DliverState"));
        [Column]
        public Guid DliverState
        {
            get { return GetProperty(DliverStateProperty); }
            set { SetProperty(DliverStateProperty, value); }
        }
		/// <summary>
        /// 是否确认
        /// </summary>
        private static PropertyInfo< string > IsSureProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("IsSure"));
        [Column]
        public string IsSure
        {
            get { return GetProperty(IsSureProperty); }
            set { SetProperty(IsSureProperty, value); }
        }
		/// <summary>
        /// 确认人
        /// </summary>
        private static PropertyInfo< Guid > SureUserProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("SureUser"));
        [Column]
        public Guid SureUser
        {
            get { return GetProperty(SureUserProperty); }
            set { SetProperty(SureUserProperty, value); }
        }
		/// <summary>
        /// 确认时间
        /// </summary>
        private static PropertyInfo< DateTime > SureTimeProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< DateTime >("SureTime"));
        [Column]
        public DateTime SureTime
        {
            get { return GetProperty(SureTimeProperty); }
            set { SetProperty(SureTimeProperty, value); }
        }
		/// <summary>
        ///  添加人
        /// </summary>
        private static PropertyInfo< Guid > AddUserProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< Guid >("AddUser"));
        [Column]
        public Guid AddUser
        {
            get { return GetProperty(AddUserProperty); }
            set { SetProperty(AddUserProperty, value); }
        }
		/// <summary>
        ///  添加时间
        /// </summary>
        private static PropertyInfo< DateTime > AddTimeProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< DateTime >("AddTime"));
        [Column]
        public DateTime AddTime
        {
            get { return GetProperty(AddTimeProperty); }
            set { SetProperty(AddTimeProperty, value); }
        }
		/// <summary>
        /// 客户负责人名称
        /// </summary>
        private static PropertyInfo< string > CustomerMgrNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("CustomerMgrName"));
        [Column]
        public string CustomerMgrName
        {
            get { return GetProperty(CustomerMgrNameProperty); }
            set { SetProperty(CustomerMgrNameProperty, value); }
        }
		/// <summary>
        /// 订单所属部门名称
        /// </summary>
        private static PropertyInfo< string > OrderofDeptNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("OrderofDeptName"));
        [Column]
        public string OrderofDeptName
        {
            get { return GetProperty(OrderofDeptNameProperty); }
            set { SetProperty(OrderofDeptNameProperty, value); }
        }
		/// <summary>
        /// 客户名称
        /// </summary>
        private static PropertyInfo< string > CustomerNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("CustomerName"));
        [Column]
        public string CustomerName
        {
            get { return GetProperty(CustomerNameProperty); }
            set { SetProperty(CustomerNameProperty, value); }
        }
		/// <summary>
        /// 行销顾问
        /// </summary>
        private static PropertyInfo< string > SaleadviserNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("SaleadviserName"));
        [Column]
        public string SaleadviserName
        {
            get { return GetProperty(SaleadviserNameProperty); }
            set { SetProperty(SaleadviserNameProperty, value); }
        }
		/// <summary>
        /// 信息专员
        /// </summary>
        private static PropertyInfo< string > AddUserNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("AddUserName"));
        [Column]
        public string AddUserName
        {
            get { return GetProperty(AddUserNameProperty); }
            set { SetProperty(AddUserNameProperty, value); }
        }
		/// <summary>
        /// 一推讲师
        /// </summary>
        private static PropertyInfo< string > LectorNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("LectorName"));
        [Column]
        public string LectorName
        {
            get { return GetProperty(LectorNameProperty); }
            set { SetProperty(LectorNameProperty, value); }
        }
		/// <summary>
        /// 高级管理顾问姓名
        /// </summary>
        private static PropertyInfo< string > NegotiateTeachNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("NegotiateTeachName"));
        [Column]
        public string NegotiateTeachName
        {
            get { return GetProperty(NegotiateTeachNameProperty); }
            set { SetProperty(NegotiateTeachNameProperty, value); }
        }
		/// <summary>
        /// 课中服务人姓名
        /// </summary>
        private static PropertyInfo< string > ClassServerNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("ClassServerName"));
        [Column]
        public string ClassServerName
        {
            get { return GetProperty(ClassServerNameProperty); }
            set { SetProperty(ClassServerNameProperty, value); }
        }
		/// <summary>
        /// 负责交付人姓名
        /// </summary>
        private static PropertyInfo< string > ClassFrontServerNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("ClassFrontServerName"));
        [Column]
        public string ClassFrontServerName
        {
            get { return GetProperty(ClassFrontServerNameProperty); }
            set { SetProperty(ClassFrontServerNameProperty, value); }
        }
       /// <summary>
        /// 客户来源
        /// </summary>
        private static PropertyInfo< string > originNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("originName"));
        [Column]
        public string originName
        {
            get { return GetProperty(originNameProperty); }
            set { SetProperty(originNameProperty, value); }
        }
		/// <summary>
        /// 确认人姓名
        /// </summary>
        private static PropertyInfo< string > SureNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("SureName"));
        [Column]
        public string SureName
        {
            get { return GetProperty(SureNameProperty); }
            set { SetProperty(SureNameProperty, value); }
        }
		/// <summary>
        /// 新建人姓名
        /// </summary>
        private static PropertyInfo< string > CreateUserNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout),new PropertyInfo< string >("CreateUserName"));
        [Column]
        public string CreateUserName
        {
            get { return GetProperty(CreateUserNameProperty); }
            set { SetProperty(CreateUserNameProperty, value); }
        }

       /// <summary>
        /// 所属行业
        /// </summary>
        private static PropertyInfo<string> TradeNameProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<string>("TradeName"));
        [Column]
        public string TradeName
        {
            get { return GetProperty(TradeNameProperty); }
            set { SetProperty(TradeNameProperty, value); }
        }
        /// <summary>
        /// 产品
        /// </summary>
        private static PropertyInfo<string> CompanyProductProperty = RegisterProperty(typeof(V_CrmDeliverMajorProductLayout), new PropertyInfo<string>("CompanyProduct"));
        [Column]
        public string CompanyProduct
        {
            get { return GetProperty(CompanyProductProperty); }
            set { SetProperty(CompanyProductProperty, value); }
        }


        
        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "IsSure");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsSure", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "CustomerMgrName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CustomerMgrName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "OrderofDeptName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("OrderofDeptName", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "CustomerName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CustomerName", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "SaleadviserName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SaleadviserName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "AddUserName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("AddUserName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "LectorName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("LectorName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "NegotiateTeachName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("NegotiateTeachName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ClassServerName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ClassServerName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ClassFrontServerName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ClassFrontServerName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "SureName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("SureName", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "CreateUserName");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("CreateUserName", 30));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public V_CrmDeliverMajorProductLayout(){}

        public static V_CrmDeliverMajorProductLayout New()
        {
            return DataPortal.Create<V_CrmDeliverMajorProductLayout>();
        }
        public static V_CrmDeliverMajorProductLayout Get(Guid ID)
        {
            return DataPortal.Fetch<V_CrmDeliverMajorProductLayout>(new SingleLazyCriteria<V_CrmDeliverMajorProductLayout, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }
        
        
        #endregion
        
        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(string Code)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);

                var data = db.Select< V_CrmDeliverMajorProductLayout>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(CodeProperty, data.Code);
                LoadProperty(OrderProductIDProperty, data.OrderProductID);
                LoadProperty(ProductLayoutIDProperty, data.ProductLayoutID);
                LoadProperty(NegotiateTeachProperty, data.NegotiateTeach);
                LoadProperty(ClassServerProperty, data.ClassServer);
                LoadProperty(ClassFrontServerProperty, data.ClassFrontServer);
                LoadProperty(DliverStateProperty, data.DliverState);
                LoadProperty(IsSureProperty, data.IsSure);
                LoadProperty(SureUserProperty, data.SureUser);
                LoadProperty(SureTimeProperty, data.SureTime);
                LoadProperty(AddUserProperty, data.AddUser);
                LoadProperty(AddTimeProperty, data.AddTime);
                LoadProperty(originNameProperty, data.originName);
                LoadProperty(CustomerMgrNameProperty, data.CustomerMgrName);
                LoadProperty(OrderofDeptNameProperty, data.OrderofDeptName);
                LoadProperty(CustomerNameProperty, data.CustomerName);
                LoadProperty(SaleadviserNameProperty, data.SaleadviserName);
                LoadProperty(AddUserNameProperty, data.AddUserName);
                LoadProperty(LectorNameProperty, data.LectorName);
                LoadProperty(NegotiateTeachNameProperty, data.NegotiateTeachName);
                LoadProperty(ClassServerNameProperty, data.ClassServerName);
                LoadProperty(ClassFrontServerNameProperty, data.ClassFrontServerName);
                LoadProperty(SureNameProperty, data.SureName);
                LoadProperty(CreateUserNameProperty, data.CreateUserName);
                LoadProperty(TradeNameProperty, data.TradeName);
                LoadProperty(CompanyProductProperty, data.CompanyProduct);
                LoadProperty(CustomercodeProperty, data.CustomerCode);
                LoadProperty(CustomerIdProperty, data.CustomerId);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(ID);
        }
        #endregion
	}
}

